package com.qf.commons.web.aspect.utils;

import com.alibaba.fastjson.JSON;

/**
 * author Ken
 * create_time 2022/11/28
 */
public class UserUtils {

    private static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void setUser(String json){
        threadLocal.set(json);
    }

    public static <T> T getUser(Class<T> cls){
        String json = threadLocal.get();
        if (json == null) return null;

        return JSON.parseObject(json, cls);
    }

    public static void clear(){
        threadLocal.remove();
    }
}
